﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MisClient
{
    public partial class FrmVariablePrice : BaseForm
    {
        private IBLL.IDepart departBLL = MisCLL.DAOFactory.CreateInstance().GetRemoteDepart();
        private IBLL.IGoods goodsBLL = MisCLL.DAOFactory.CreateInstance().GetRemoteGoods();

        public FrmVariablePrice()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            this.txtDDNo.Clear();
            this.txtOperUser.Text = accountUser.UserCode;
            this.txtDate.Text = DateTime.Now.ToShortDateString();
            this.txtOper.Text = accountUser.UserCode;
            this.txtDepCode.Text = "1";
            this.txtBoxDep.Clear();
            this.dataGridView1.Rows.Clear();

            this.txtID.Clear();
            this.txtGoods.Clear();
            this.txtDM.Clear();
            this.txtSl3.Clear();
            this.textBox2.Clear();
            this.textBox3.Clear();
            this.txtTotalNum.Clear();

            this.txtDDNo.Enabled = true;
            this.txtDepCode.Enabled = true;
            this.txtOper.Enabled = true;
            this.txtID.Enabled = false;
            this.textBox3.Enabled = false;
            this.txtTotalNum.Enabled = false;

            this.btnAdd.Enabled = false;
            this.btnAddRecord.Enabled = false;
            this.btnDelRecord.Enabled = false;
            this.btnPrint.Enabled = false;
            this.btnRef.Enabled = true;
            this.btnQuit.Enabled = false;
            this.btnSave.Enabled = false;
            this.btnCan.Enabled = true;
            this.txtDDNo.Focus();
        }

        private void FrmVariablePrice_Load(object sender, EventArgs e)
        {
            this.txtDDNo.Focus();
        }

        private void txtDDNo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (string.IsNullOrEmpty(this.txtDDNo.Text.Trim()))
                {
                    MessageBox.Show("原始单号不能为空！", "信息窗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.txtDDNo.Focus();
                    return;
                }
                this.txtDepCode.Focus();
            }
        }

        private void txtOper_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (string.IsNullOrEmpty(this.txtDDNo.Text.Trim()))
                {
                    MessageBox.Show("原始单号不能为空！", "信息窗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.txtDDNo.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(this.txtDepCode.Text.Trim()))
                {
                    MessageBox.Show("部门代码不能为空！", "信息窗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.txtDepCode.Focus();
                    return;
                }
                MisModel.Depart depart = departBLL.GetById(this.txtDepCode.Text.Trim());
                if (depart == null)
                {
                    MessageBox.Show("此部门无权操作！", "信息窗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.txtDepCode.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(this.txtOper.Text.Trim()))
                {
                    MessageBox.Show("物价员不能为空！", "信息窗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.txtOper.Focus();
                    return;
                }
                this.txtDDNo.Enabled = false;
                this.txtDepCode.Enabled = false;
                this.txtOper.Enabled = false;
                this.txtID.Enabled = true;
                this.textBox3.Enabled = true;
                this.txtTotalNum.Enabled = true;

                this.btnAdd.Enabled = false;
                this.btnAddRecord.Enabled = true;
                this.btnDelRecord.Enabled = true;
                this.btnPrint.Enabled = false;
                this.btnRef.Enabled = true;
                this.btnQuit.Enabled = false;
                this.btnSave.Enabled = true;
                this.btnCan.Enabled = true;
                this.txtID.Focus();
            }
            
        }

        private void txtDepCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (string.IsNullOrEmpty(this.txtDepCode.Text.Trim()))
                {
                    MessageBox.Show("部门代码不能为空！", "信息窗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.txtDepCode.Focus();
                    return;
                }
                MisModel.Depart depart = departBLL.GetById(this.txtDepCode.Text.Trim());
                if (depart == null)
                {
                    MessageBox.Show("此部门无权操作！", "信息窗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.txtDepCode.Focus();
                    return;
                }
                this.txtBoxDep.Text = depart.DepName;
                this.txtOper.Focus();
            }
        }

        private void txtID_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (string.IsNullOrEmpty(this.txtID.Text.Trim()))
                {
                    MessageBox.Show("请输入合法的商品条码！", "信息窗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MisEntity.Goods entity = goodsBLL.FindByCode(this.txtID.Text.Trim());
                    if (entity == null)
                    {
                        MessageBox.Show("无此商品，请先设置！", "信息窗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        
                    }

                }
            }
        }
    }
}
